var information={};
$(function(){
	getAllFiniCom(null);
	initTaskDis();
	requestDepartment();
	requestSort();
	 //分页，首页
	  $("#headPage").click(function(){ 
		information.currentPage=1;
	  	$("#totalPage").html(information.currentPage+"/"+information.totalPage);
	  	getAllFiniCom(information);
	  })
	  
	  $(document).on("click",".detail",function(){
		  var id= $(this).attr("data-id");
			var menuId=$("#menu-container").attr("menu-id");
			window.location.href = '../information/commentDetailInfo.jsp?menuId='+menuId+'&detailId=' + id;
	  })

	  //分页，尾页
	  $("#endPage").click(function(){
	  	$("#totalPage").html(information.totalPage+"/"+information.totalPage);
	  	information.currentPage=totalPage;
	  	getAllFiniCom(information);
	  })
	  //分页，上一页
	  $("#prevPage").click(function(){
	  	if(information.currentPage<=1)
	  	{
	  		information.currentPage=1;
	  	}
	  	else
	  	{
	  		information.currentPage=information.currentPage-1;
	  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);  
	  		getAllFiniCom(information);
	  	}

	 })
	 
	  //分页，下一页
	   $("#nextPage").click(function(){
	  	
	  	if(information.currentPage>=information.totalPage)
	  	{
	  		information.currentPage=information.currentPage;
	  	}
	  	else
	  	{
	  		information.currentPage=information.currentPage+1;
	  		$("#totalPage").html(information.currentPage+"/"+information.totalPage);
	  		getAllFiniCom(information);
	  	}
	  	
	  })
});
//查询向后台请求部门信息
function requestDepartment()
{	var url="getDepartmentAndArea.do";//分口地址

	var data={};
	var object={};
	data=YuXi.util.get(url,null,function(data){
		object=data.object;
	
		//用data循环添加部门信息	
		for(var i=0;i<object.length;i++)
		{
			 var html="<option  value="+object[i].id+">"+object[i].name+"</option>";
			 $(".reDepartment").append(html);
		}
		
	},function(){});//请求数据
	
}

/*获取所有已点评的信息*/
function getAllFiniCom(data){
	
	 YuXi.util.get("getCommentRecord.do",data,function(data){
		 information.currentPage=data.currentPage;
		 information.totalPage=data.totalPage;
		 $("#totalPage").html(information.currentPage+"/"+information.totalPage);
		 var object=data.list;
		 $("tbody").html("");
		for(var i=0;i<object.length;i++){			
			var time=YuXi.getTime.get(object[i].createTime);
			var context="";
			if(object[i].content.length>15){
				context=object[i].content.substring(0,12)+"...";
			}else{
				context=object[i].content;
			}
			
			var completeContent="";
			if( object[i].completeContent!=undefined){
				if(object[i].completeContent.length>15){
					completeContent=object[i].completeContent.substring(0,12)+"...";
				}else{
					completeContent=object[i].completeContent;
				}
			}else{
				completeContent=" ";
			}
			
			var html='<tr>'+
				'<td>'+(i+1)+'</td>'+
				
	        	'<td>'+object[i].userName+'</td>'+
	        	'<td>'+context+'</td>'+
	        	'<td>'+completeContent+'</td>'+
	        	'<td>'+time+'</td>'+
	            '<td>'+
	                '<span  class=" detail btn btn-xs btn-primary" data-id="'+object[i].informationId+'">查看详情</span>'+
	            '</td>'+
	        '</tr>';
			$("tbody").append(html);
		}
		YuXi.graded.get();
		
	});
}
/*跳转到信息详情页面*/
function toComDetail(id){
	 window.location.href='commitDetail.jsp?detailId='+id;
}

function initTaskDis(){
	 YuXi.util.get("getAllInformationClassification.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".reSearchpes").append("<option value='"+obj[i].id+"' >"+obj[i].name+"</option>");
			 }
			 
		 }
	 });
	 
	 YuXi.util.get("getAllInformationPort.do",null,function(data){
		 if(data.status){
			 var obj=data.object;
			 for(var i=0;i<obj.length;i++){
				 $(".task-port").append("<option value='"+obj[i].id+"' >"+obj[i].portName+"</option>");
			 }
			 
		 }
	 });
	
}
$("#firstSearch").click(function(){
	firstSearch();
});
//简介，分级，渠道，状态，时间（今天,一周...）查找
function firstSearch()
{
	//information={};
		
		
		
	information.qualityId=$(".reinputDian option:selected").val();//录入点评
	information.completeId=$(".refinishDian option:selected").val();//完成点评
	var array=[];
	var starTime="";	
	var endTime="";
	starTime=$("#submitstarTime").val();//提交起始时间
	endTime=$("#submitendTime").val();//提交结束时间
	array = YuXi.timestamp.get(starTime,endTime, null);
	if(array[0]!=null)
	information.startTimestamp = array[0];
	if(array[1]!=null)
	information.endTimestamp = array[1];
	

	
		

		
		information.currentPage=1;
	

	getAllFiniCom(information);
	
	
}

//向后台请求分类信息
function requestSort(){	
	var url="getAllInfomationSort.do";//分类地址
	var data={};
	var object={};
	data=YuXi.util.get(url,"null",function(data){
		object=data.object;
		//用data循环添加分类信息
		for(var i=0;i<object.length;i++)
		{
			var html="<option  value="+object[i].id+" >"+object[i].name+"</option>";
			$(".reSearchsort").append(html);
		}
	},function(){
		
	});//请求数据
	
	}